package es.uca.plii.warrenl0;

// Lexer code generaled by JFlex

%%

%class WarrenExpLexer
%implements WarrenExpParser.Lexer
%public

%{ 

   /**
   * Este objeto guarda el valor semántico del Último token escaneado.
   */
   private Object lVal = null;
   
   /**
     * Method to retrieve the semantic value of the last scanned token.
     * @return the semantic value of the last scanned token.  */
    public Object getLVal ()
	{
		return lVal;
	}

    /**
     * Entry point for error reporting.  Emits an error
     * in a user-defined way.
     *
     * 
     * @param s The string for the error message.  */
     public void yyerror (String s)
	 {
		System.out.println("Ha habido un error: " + s);
	 }
 
%}

%int
%eofval{
  return 0;
%eofval}
%eofclose
%unicode

/* main character classes */
LineTerminator = \r|\n|\r\n
InputCharacter = [^\r\n]

/* identifiers */
variable = [:uppercase:][:jletterdigit:]*
functor = [:lowercase:][:jletterdigit:]*


/* Ignorar los espacios en blanco y los saltos de linea */
LineTerminator = \r|\n|\r\n
WhiteSpace = {LineTerminator} | [ \t\f]

/* comentarios */
Comment = {TraditionalComment} | {EndOfLineComment}

TraditionalComment = "/*" [^*] ~"*/" | "/*" "*"+ "/"
EndOfLineComment = "//" {InputCharacter}* {LineTerminator}?



%%

<YYINITIAL> {

  {variable}                    { lVal= new String(yytext()); return WarrenExpParser.VARIABLE;}
  {functor}                     { lVal= new String(yytext()); return WarrenExpParser.FUNCTOR;}
  ";"                           { lVal= null; return WarrenExpParser.PUNTOYCOMA;}
  ","                           { lVal= null; return WarrenExpParser.COMA;}
  "-?"                           { lVal= null; return WarrenExpParser.QUERYPROMPT; }
  "("                           { lVal= null; return WarrenExpParser.PARIZQ; }
  ")"                           { lVal= null; return WarrenExpParser.PARDCH; }
  "\."                          { lVal = null; return WarrenExpParser.PUNTO; }

  /* comments */
  {Comment}                      { /* ignore */ }

    /* whitespace */
  {WhiteSpace}                   { /* ignore */ }
    /* error cuando en entrada aparecen caracteres no propios de expresiones lambda */
  .				 {System.out.println("Error lexico carcater " + yytext() + " desconocido.");}

 }
